<?php
    //conecting to database
    $config = fopen("config.ini", "r");
    $ip = trim(split("=", fgets($config))[1]);
    $puerto = trim(split("=", fgets($config))[1]);
    $user = trim(split("=", fgets($config))[1]);
    $pass = trim(split("=", fgets($config))[1]);
    $db = trim(split("=", fgets($config))[1]);

    $con = mysqli_connect($ip, $user, $pass, $db, $puerto);
    
    // Check connection
    if (mysqli_connect_errno($con)){
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    if(!isset($_COOKIE["idEmpresa"])){
        $query = "select * from Empresa where E_Nombre=\"" . $empresa . "\"";
        $res = mysqli_query($con, $query);
        $row = mysqli_fetch_array($res);
        $idEmpresa = $row["idEmpresa"];
        setcookie("idEmpresa", "$idEmpresa", time()+60*60*8);
    }
?>
